package com.coursehub.exercise.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 学生练习关联实体
 */
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "student_exercise")
public class StudentExercise {
    
    @EmbeddedId
    private StudentExerciseId id;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "state", nullable = false)
    private ExerciseState state;
    
    @Column(name = "student_score", nullable = false)
    private Integer studentScore = 0;
    
    @MapsId("exerciseId")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "exercise_id", nullable = false, insertable = false, updatable = false)
    private Exercise exercise;
    
    public StudentExercise(StudentExerciseId id, ExerciseState state, Exercise exercise) {
        this.id = id;
        this.state = state;
        this.exercise = exercise;
    }
    
    public enum ExerciseState {
        unsubmitted, submitted, marked
    }
}